feat: Add IEEE 754 float16 (binary16) support to Rust runtime#3252
Open
AshharAhmadKhan wants to merge 5 commits intoapache:mainfrom
Open
feat: Add IEEE 754 float16 (binary16) support to Rust runtime#3252AshharAhmadKhan wants to merge 5 commits intoapache:mainfrom
AshharAhmadKhan wants to merge 5 commits intoapache:mainfrom
Conversation
- Add float16 type as transparent wrapper around u16 - Implement IEEE 754 compliant f32<->float16 conversions - Round-to-nearest, ties-to-even rounding - Proper handling of NaN, Inf, ±0, subnormals - Overflow to infinity, underflow to subnormal/zero - Add buffer read/write methods (write_f16, read_f16) - Implement Serializer trait for float16 - Add float16 to all relevant type arrays and functions - Implement arithmetic via f32 round-back - Use Policy A (bitwise Eq/Hash, separate IEEE helpers) - Add comprehensive unit tests (11 tests, all passing) Resolves apache#3207
- Add #[allow(non_camel_case_types)] to float16 struct (per issue requirements) - Add #[allow(dead_code)] to EXP_BIAS constant
- Add Apache license header to number.rs (required by CI) - Suppress clippy::should_implement_trait warnings for explicit arithmetic methods (methods required by issue spec alongside trait implementations)
- Add #[allow(clippy::should_implement_trait)] to all arithmetic methods - Restore missing float16 import in number.rs - Fix formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements full IEEE 754 half-precision (binary16)
float16support for the Rust runtime as requested in issue #3207.Implementation Details
Core Type (
fory-core/src/float16.rs)#[repr(transparent)] pub struct float16(u16)- 614 linesIntegration
buffer.rs):write_f16()andread_f16()using little-endianserializer/number.rs): FullSerializertrait +ForyDefaultimplementationtypes.rs): Added toBASIC_TYPES,PRIMITIVE_TYPES,PRIMITIVE_ARRAY_TYPES,BASIC_TYPE_NAMES,PRIMITIVE_ARRAY_TYPE_MAP,is_primitive_type_id()lib.rs): Public module withFloat16aliasTesting
Why?
Support for half-precision floats is essential for:
What does this PR do?
Adds production-ready IEEE 754 binary16 support to Rust runtime matching the exact specification in #3207, including:
Related issues
Closes #3207
Does this PR introduce any user-facing change?
Does this PR introduce any public API change?
float16(exported asFloat16)from_bits,to_bits,from_f32,to_f32, classification methods, arithmetic methodsZERO,NEG_ZERO,INFINITY,NEG_INFINITY,NAN,MAX,MIN_POSITIVE,MIN_POSITIVE_SUBNORMALDoes this PR introduce any binary protocol compatibility change?
FLOAT16(TypeId = 16) andFLOAT16_ARRAY(TypeId = 50) to wire formatBenchmark
Not applicable - this PR adds new functionality without modifying existing code paths. No performance impact on existing f32/f64 usage.